1 using System.Collections.Generic;
2 using UnityEngine;
3
4 namespace ProceduralToolkit
5 {
6 public static partial class MeshE
7 {
8 #region Mesh parts
9
10 public static Mesh Triangle(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2)
11 {
12 var normal = Vector3.Cross((vertex1 - vertex0), (vertex2 - vertex0)).normalized;
13 return new Mesh
14 {
15 vertices = new[] {vertex0, vertex1, vertex2},
16 normals = new[] {normal, normal, normal},
17 uv = new[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)},
18 triangles = new[] {0, 1, 2},
19 name = "Triangle"
20 };
21 }
22
23 public static Mesh Quad(Vector3 origin, Vector3 width, Vector3 length)
24 {
25 var normal = Vector3.Cross(length, width).normalized;
26 return new Mesh
27 {
28 vertices = new[] {origin, origin + length, origin + length + width, origin + width},
29 normals = new[] {normal, normal, normal, normal},
30 uv = new[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0)},
31 triangles = new[] {0, 1, 2, 0, 2, 3},
32 name = "Quad"
33 };
34 }
35
36 public static Mesh Quad(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3)
37 {
38 var normal = Vector3.Cross((vertex1 - vertex0), (vertex2 - vertex0)).normalized;
39 return new Mesh
40 {
41 vertices = new[] {vertex0, vertex1, vertex2, vertex3},
42 normals = new[] {normal, normal, normal, normal},
43 uv = new[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0)},
44 triangles = new[] {0, 1, 2, 0, 2, 3},
45 name = "Quad"
46 };
47 }
48
49 public static Mesh TriangleFan(List<Vector3> vertices)
50 {
51 return MeshDraft.TriangleFan(vertices).ToMesh();
52 }
53
54 public static Mesh TriangleStrip(List<Vector3> vertices)
55 {
56 return MeshDraft.TriangleStrip(vertices).ToMesh();
57 }
58
59 #endregion Mesh parts
60
61 #region Platonic solids
62
63 public static Mesh Tetrahedron(float radius)
64 {
65 return MeshDraft.Tetrahedron(radius).ToMesh();
66 }
67
68 public static Mesh Cube(float side)
69 {
70 return MeshDraft.Cube(side).ToMesh();
71 }
72
73 public static Mesh Hexahedron(float width, float length, float height)
74 {
75 return MeshDraft.Hexahedron(width, length, height).ToMesh();
76 }
77
78 public static Mesh Hexahedron(Vector3 width, Vector3 length, Vector3 height)
79 {
80 return MeshDraft.Hexahedron(width, length, height).ToMesh();
81 }
82
83 public static Mesh Octahedron(float radius)
84 {
85 return MeshDraft.Octahedron(radius).ToMesh();
86 }
87
88 public static Mesh Dodecahedron(float radius)
89 {
90 return MeshDraft.Dodecahedron(radius).ToMesh();
91 }
92
93 public static Mesh Icosahedron(float radius)
94 {
95 return MeshDraft.Icosahedron(radius).ToMesh();
96 }
97
98 #endregion Platonic solids
99
100 public static Mesh Plane(float xSize = 1, float zSize = 1, int xSegments = 1, int zSegments = 1)
101 {
102 return MeshDraft.Plane(xSize, zSize, xSegments, zSegments).ToMesh();
103 }
104
105 public static Mesh Pyramid(float radius, int segments, float height, bool inverted = false)
106 {
107 return MeshDraft.Pyramid(radius, segments, height, inverted).ToMesh();
108 }
109
110 public static Mesh Prism(float radius, int segments, float height)
111 {
112 return MeshDraft.Prism(radius, segments, height).ToMesh();
113 }
114
115 public static Mesh Cylinder(float radius, int segments, float height)
116 {
117 return MeshDraft.Cylinder(radius, segments, height).ToMesh();
118 }
119
120 public static Mesh FlatSphere(float radius, int horizontalSegments, int verticalSegments)
121 {
122 return MeshDraft.FlatSphere(radius, horizontalSegments, verticalSegments).ToMesh();
123 }
124
125 public static Mesh Sphere(float radius, int horizontalSegments, int verticalSegments)
126 {
127 return MeshDraft.Sphere(radius, horizontalSegments, verticalSegments).ToMesh();
128 }
129
130 public static Mesh FlatSpheroid(float radius, float height, int horizontalSegments, int verticalSegments)
131 {
132 return MeshDraft.FlatSpheroid(radius, height, horizontalSegments, verticalSegments).ToMesh();
133 }
134
135 public static Mesh Spheroid(float radius, float height, int horizontalSegments, int verticalSegments)
136 {
137 return MeshDraft.Spheroid(radius, height, horizontalSegments, verticalSegments).ToMesh();
138 }
139
140 public static Mesh FlatTeardrop(float radius, float height, int horizontalSegments, int verticalSegments)
141 {
142 return MeshDraft.FlatTeardrop(radius, height, horizontalSegments, verticalSegments).ToMesh();
143 }
144
145 public static Mesh Teardrop(float radius, float height, int horizontalSegments, int verticalSegments)
146 {
147 return MeshDraft.Teardrop(radius, height, horizontalSegments, verticalSegments).ToMesh();
148 }
149 }
150 }